package com.myh.cc.coom.ranking.adapter

import android.content.Context
import android.support.v7.widget.RecyclerView
import android.text.Html
import android.view.LayoutInflater
import android.view.ViewGroup
import com.bumptech.glide.Glide
import com.myh.cc.coom.ranking.bean.RankingBean
import com.myh.cc.databinding.ItemRankingRvBinding
import com.myh.cc.widget.OnItemClickListener


/**
 * des    ：
 * create    ：  mayahao.
 * date   ：  2018/1/13.   ：
 */
class RankingAdapter(bean: RankingBean,contet: Context) : RecyclerView.Adapter<RankingAdapter.VH>(){

    val context = contet
    val bean = bean
    lateinit var mListener: OnItemClickListener

    override fun onBindViewHolder(holder: VH, position: Int) {

        val  topL = bean.data.topList

        Glide.with(context).load(topL[position].picUrl).into(holder.binding.itemIvIcon)

        holder.binding.tvTopTitle.setText(topL[position].topTitle)

        holder.binding.tvOne.text =Html.fromHtml("1."+topL[position].songList[0].songname+" - "+"<font color='#A0A0A0'>"+topL[position].songList[0].singername+"</font>")

        holder.binding.tvTwo.text =Html.fromHtml("2."+topL[position].songList[1].songname+" - "+"<font color='#A0A0A0'>"+topL[position].songList[1].singername+"</font>")

        //holder.binding.tvThree.text ="3."+topL[position].songList[2].songname+" - "+topL[position].songList[2].singername

        holder.binding.tvThree.text=Html.fromHtml("3."+topL[position].songList[2].songname+" - "+"<font color='#A0A0A0'>"+topL[position].songList[2].singername+"</font>")

        holder.binding.root.setOnClickListener{
            view ->
            mListener?.onClick(view,position)
        }

    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): VH {
        return VH.create(LayoutInflater.from(parent.context), parent);
    }

    override fun getItemCount(): Int {
            return bean.data.topList.size
    }


    class VH(binding: ItemRankingRvBinding): RecyclerView.ViewHolder(binding.root){

        val binding = binding

        companion object {
            fun create(inflater: LayoutInflater, parent: ViewGroup): RankingAdapter.VH {
                val binder = ItemRankingRvBinding.inflate(inflater, parent, false)
                return RankingAdapter.VH(binder)
            }
        }

    }
}